package com.ztstkj.lzboard.adapters

import android.graphics.Color
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.ztstkj.lzboard.R
import com.ztstkj.lzservices.dto.boards.BoardExchangeOutput


class UserExchangeAdapter(private var datas: List<BoardExchangeOutput>): RecyclerView.Adapter<UserExchangeAdapter.ItemViewHolder>() {
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder {
        val v = LayoutInflater.from(parent.context)
            .inflate(R.layout.exchange_item, parent, false)
        return ItemViewHolder(v)
    }

    override fun onBindViewHolder(holder: ItemViewHolder, position: Int) {
        val bean = datas[position]
        if(position%2==1){
            holder.itemView.setBackgroundResource(R.drawable.table_bg_odd) // 偶数行颜色
        }

        holder.exchangeRoom.text  = bean.home
        holder.exchangeGood.text  = bean.productName
        holder.exchangePoint.text = bean.point.toString()
        holder.exchangeTime.text=bean.createTimeAbb
    }

    override fun getItemCount(): Int {
        return datas.size
    }


    inner class ItemViewHolder(view: View): RecyclerView.ViewHolder(view){
        val exchangeRoom : TextView = view.findViewById(R.id.tvExchangeRoom)
        val exchangeGood : TextView = view.findViewById(R.id.tvExchangeGood)
        val exchangePoint : TextView = view.findViewById(R.id.tvExchangePoint)
        val exchangeTime : TextView = view.findViewById(R.id.tvExchangeTime)
    }
}